package com.bbva.kyfb.kyfbjpatlsb.dominiotlsb;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class Ttlnemfd.
 */
@Entity
@Table(name = "TTLNEMFD",schema = "TLNE")
@Configurable
@RooJavaBean
@RooToString
@RooEntity(identifierType = TtlnemfdPK.class, versionField = "",  persistenceUnit="persistenceUnitTLSB", table = "TTLNEMFD", schema = "TLNE")
@RooDbManaged(automaticallyDelete = true)
public class Ttlnemfd {

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AudFmodific: ").append(getAudFmodific()).append(", ");
        sb.append("AudUsuario: ").append(getAudUsuario()).append(", ");
        sb.append("CodFamilia: ").append(getCodFamilia()).append(", ");
        sb.append("CodSubfamil: ").append(getCodSubfamil()).append(", ");
        sb.append("DesProd: ").append(getDesProd()).append(", ");
        sb.append("Id: ").append(getId()).append(", ");
        sb.append("XtiVenta: ").append(getXtiVenta());
        return sb.toString();
    }

	/** The cod familia. */
	@Column(name = "COD_FAMILIA",columnDefinition = "CHAR")
    @NotNull
    private Character codFamilia;

	/** The cod subfamil. */
	@Column(name = "COD_SUBFAMIL",columnDefinition = "SMALLINT")
    @NotNull
    private Short codSubfamil;

	/** The xti venta. */
	@Column(name = "XTI_VENTA",columnDefinition = "CHAR")
    @NotNull
    private Character xtiVenta;

	/** The des prod. */
	@Column(name = "DES_PROD", length = 60,columnDefinition = "CHAR")
    private String desProd;

	/** The aud usuario. */
	@Column(name = "AUD_USUARIO", length = 8,columnDefinition = "CHAR")
    private String audUsuario;

	/** The aud fmodific. */
	@Column(name = "AUD_FMODIFIC",columnDefinition = "DATE")
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date audFmodific;

	/**
	 * Gets the cod familia.
	 *
	 * @return the cod familia
	 */
	public Character getCodFamilia() {
        return this.codFamilia;
    }

	/**
	 * Sets the cod familia.
	 *
	 * @param codFamilia the new cod familia
	 */
	public void setCodFamilia(Character codFamilia) {
        this.codFamilia = codFamilia;
    }

	/**
	 * Gets the cod subfamil.
	 *
	 * @return the cod subfamil
	 */
	public Short getCodSubfamil() {
        return this.codSubfamil;
    }

	/**
	 * Sets the cod subfamil.
	 *
	 * @param codSubfamil the new cod subfamil
	 */
	public void setCodSubfamil(Short codSubfamil) {
        this.codSubfamil = codSubfamil;
    }

	/**
	 * Gets the xti venta.
	 *
	 * @return the xti venta
	 */
	public Character getXtiVenta() {
        return this.xtiVenta;
    }

	/**
	 * Sets the xti venta.
	 *
	 * @param xtiVenta the new xti venta
	 */
	public void setXtiVenta(Character xtiVenta) {
        this.xtiVenta = xtiVenta;
    }

	/**
	 * Gets the des prod.
	 *
	 * @return the des prod
	 */
	public String getDesProd() {
        return this.desProd;
    }

	/**
	 * Sets the des prod.
	 *
	 * @param desProd the new des prod
	 */
	public void setDesProd(String desProd) {
        this.desProd = desProd;
    }

	/**
	 * Gets the aud usuario.
	 *
	 * @return the aud usuario
	 */
	public String getAudUsuario() {
        return this.audUsuario;
    }

	/**
	 * Sets the aud usuario.
	 *
	 * @param audUsuario the new aud usuario
	 */
	public void setAudUsuario(String audUsuario) {
        this.audUsuario = audUsuario;
    }

	/**
	 * Gets the aud fmodific.
	 *
	 * @return the aud fmodific
	 */
	public Date getAudFmodific() {
        return this.audFmodific;
    }

	/**
	 * Sets the aud fmodific.
	 *
	 * @param audFmodific the new aud fmodific
	 */
	public void setAudFmodific(Date audFmodific) {
        this.audFmodific = audFmodific;
    }
	
	/** The entity manager. */
	@PersistenceContext(unitName="persistenceUnitTLSB")
    transient EntityManager entityManager;

	/** The id. */
	@EmbeddedId
    private TtlnemfdPK id;

	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public TtlnemfdPK getId() {
        return this.id;
    }

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(TtlnemfdPK id) {
        this.id = id;
    }

	/**
	 * Persist.
	 */
	@Transactional(value="tlsb")
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	/**
	 * Removes the.
	 */
	@Transactional(value="tlsb")
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Ttlnemfd attached = Ttlnemfd.findTtlnemfd(this.id);
            this.entityManager.remove(attached);
        }
    }

	/**
	 * Flush.
	 */
	@Transactional(value="tlsb")
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	/**
	 * Clear.
	 */
	@Transactional(value="tlsb")
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	/**
	 * Merge.
	 *
	 * @return the ttlnemfd
	 */
	@Transactional(value="tlsb")
    public Ttlnemfd merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Ttlnemfd merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	/**
	 * Entity manager.
	 *
	 * @return the entity manager
	 */
	public static final EntityManager entityManager() {
        EntityManager em = new Ttlnemfd().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	
	/**
	 * Count ttlnemfds.
	 *
	 * @return the long
	 */
	@Transactional(value="tlsb")
	public static long countTtlnemfds() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Ttlnemfd o", Long.class).getSingleResult();
    }

	
	/**
	 * Find all ttlnemfds.
	 *
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Ttlnemfd> findAllTtlnemfds() {
        return entityManager().createQuery("SELECT o FROM Ttlnemfd o", Ttlnemfd.class).getResultList();
    }

	
	/**
	 * Find ttlnemfd.
	 *
	 * @param id the id
	 * @return the ttlnemfd
	 */
	@Transactional(value="tlsb")
	public static Ttlnemfd findTtlnemfd(TtlnemfdPK id) {
        if (id == null) return null;
        return entityManager().find(Ttlnemfd.class, id);
    }

	
	/**
	 * Find ttlnemfd entries.
	 *
	 * @param firstResult the first result
	 * @param maxResults the max results
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Ttlnemfd> findTtlnemfdEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Ttlnemfd o", Ttlnemfd.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
}
